package com.woniuxy.shop.dao;

import com.woniuxy.shop.entity.TopAddress;

/**
*@author 作者：
*version 创建时间：
*类说明：
*/
public class TopAddressDao {
	
	/**
	 * 添加地址
	 * @param ta
	 */
	public void add(TopAddress ta) {
		String sql = "insert into user_top_address(name,parentid) values(?,?)";
		Object[] obs = {ta.getName(),ta.getParentid()};
		DbHelper.excuteSQL(sql, obs);
	}
	
	/**
	 * 根据指定ID查询其详细
	 * @param id
	 * @return
	 */
	public TopAddress getTopByID(int id){
		TopAddress address = new TopAddress();
		String sql = "select * from user_top_address where id=?";
		address = DbHelper.executeQueryForSingleRow(sql, TopAddress.class, id);
		return address;
	}

	/**
	 * 根据父ID和name获取Top
	 * @param name
	 * @param pid
	 * @return
	 */
	public TopAddress getTopByNameAndId(String name, int pid) {
		String sql = "select * from user_top_address where name=? and parentid=?";
		return DbHelper.executeQueryForSingleRow(sql, TopAddress.class, name,pid);
	}
}
